package our.pack;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MediaAdapter extends ArrayAdapter<MetaData> {
	
	private LayoutInflater inflater;

	public MediaAdapter(Context context, int textViewResourceId, List<MetaData> objects) {
		super(context, textViewResourceId, objects);
		inflater = LayoutInflater.from(context);
		// TODO Auto-generated constructor stub
	}

	/**
	 * kijkt naar het type van de metadata en zet het er de goede image bij
	 */
	@Override
	public View getView(int p, View v, ViewGroup parent)
	{
		if( v == null )
		{
			v = inflater.inflate(R.layout.mediaview, null);
		}
		
		MetaData m = getItem(p);
		if( m != null)
		{
			TextView mediaNaam = (TextView)v.findViewById(R.id.textMediaName);
			TextView mediaDate = (TextView)v.findViewById(R.id.mediaDate);
			ImageView mediaPic = (ImageView)v.findViewById(R.id.mediaImageView);
			
			mediaNaam.setText(m.getName());
			mediaDate.setText(m.getDate());
			
			if(m.getType().equals("photo")) {
				mediaPic.setImageResource(R.drawable.jpeg);
			}
			else if(m.getType().equals("audio")) {
				mediaPic.setImageResource(R.drawable.audio_cd);
			}
			else if(m.getType().equals("text")) {
				mediaPic.setImageResource(R.drawable.textdocument);
			}
			else if(m.getType().equals("video")) {
				mediaPic.setImageResource(R.drawable.video);
			}
			
			
		}
		return v;
	}

}
